package com.ccubee.data.transfer;


import com.ccubee.data.transfer.event.EventTypeContext;
import com.ccubee.data.transfer.properties.CanalClientProperties;
import com.ccubee.data.transfer.properties.DataProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;

/**
 * @Author ycf
 * @Date 2022/5/22 00:17
 * @Version 1.0
 */
@Configuration
@ComponentScan("com.ccubee.data.transfer")
public class DataTransferAutoconfigure {
    @ConfigurationProperties(prefix = DataProperties.PREFIX)
    @Bean
    public DataProperties dataProperties() {
        return new DataProperties();
    }


    @Bean
    public EventTypeContext eventTypeContext() {
        return new EventTypeContext();
    }

    @ConditionalOnProperty(prefix = CanalClientProperties.PREFIX, name = "enabled", havingValue = "true")
    public static class CanalAutoconfigure {

        @Bean
        public CanContext canContext(DataProperties dataProperties, TaskExecutor taskExecutor) {
            return new CanContext(dataProperties, taskExecutor);
        }
    }
}
